apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../swiper"],function(V,$api,$,app,service,Swiper){
  var vm = {
    el: '.container',
    data: {
      divideInfo: {},
      divideList: [],
      page: 1,
      hasMoreData: true
    },
    created: function () {
      var that = this;
      this.init();

      // 触底
      api.addEventListener({
          name: 'scrolltobottom',
          extra:{
              threshold:0
          }
      }, function(ret, err){
          that.scrolltobottom()
      });
      // 刷新
      app.refreshHeaderInfo(function(){
      	that.divideList = [];
      	that.page = 1;
      	that.init();
      });

      api.addEventListener({
      	name: 'withdraw_'
      },function(){
      	that.divideList = [];
      	that.page = 1;
      	that.init();
      });
    },
    methods: {
      init: function () {
        var that = this;
        this.getDivideInfo();
        this.getDivideList();
      },

      // 获取个人分成信息
      getDivideInfo: function () {
        var that = this;
        app.ajax(
          service['beneFit'],
          {
            data: {
              values: {
                unionid: $api.getStorage("shop_unionid")
              }
            }
          },
          function (res) {
            if (res.code == 0) {
              that.divideInfo = res.data;
            } else {
              api.toast({
                  msg: res.message,
                  duration: 2000,
                  location: 'bottom'
              });
            }
          }
        );
      },

      // 获取分成明细
      getDivideList: function () {
        var that = this;
        app.ajax(
          service['beneFitLog'],
          {
            data: {
              values: {
                unionid: $api.getStorage("shop_unionid"),
                page: that.page
              }
            }
          },
          function (res) {
            if (res.code == 0) {
              if (res.data.length > 0) {
                that.hasMoreData = true;
                for (var i = 0, len = res.data.length; i < len; i++) {
                  that.divideList.push(res.data[i]);
                }
              } else {
                that.hasMoreData = false;
              }
            } else {
              api.toast({
                  msg: res.message,
                  duration: 2000,
                  location: 'bottom'
              });
            }
          }
        );
      },

      // 前往提现页面
      toDrawOut: function (){
        // do something...
        app.openWin('buyWithdraw');
      },

      // 前往提现记录页面
      toDrawOutDetail: function () {
        app.openWin('drawoutHistory');
      },

      // 加载更多
      scrolltobottom: function () {
        if (this.hasMoreData) {
          this.page += 1;
          this.getDivideList();
        }
      }
    }
  }
  var even = function() {}
  var newVue = new Vue(vm);
  even();
});
}
